package cn.fulong.frame.listener;

import cn.fulong.frame.config.Platform;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Slf4j
public class ContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {

        log.info("平台初始化开始...");
        ServletContext context = event.getServletContext();

        try {
            Platform.getInstance().init(context);
            log.info("平台初始化结束.");
        } catch (Exception e) {
            log.error("平台初始化失败.");
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.info("Destroy servlet context");
    }
}
